﻿<sticky:StickyWindowBase xmlns:sticky="clr-namespace:Squiggle.UI.StickyWindow" 
                     x:Class="Squiggle.UI.Windows.ChatWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:controls="clr-namespace:Squiggle.UI.Controls"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Squiggle.UI"
    Title="ChatWindow" x:Name="chatWindow"
    xmlns:dragdrop="clr-namespace:FluidKit.Helpers.DragDrop;assembly=FluidKit"     
    Loaded="Window_Loaded" Activated="Window_Activated" KeyDown="Window_KeyDown"
    SizeChanged="Window_SizeChanged" Icon="/Squiggle;component/Images/chat.ico">
    <sticky:StickyWindowBase.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Resources/Expanders.xaml" />
                <ResourceDictionary>
                    <controls:ChatDragDropAdvisor x:Key="contactDragDrop" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </sticky:StickyWindowBase.Resources>
    <Grid Background="#FFF3F3F3" x:Name="LayoutRoot" 
          dragdrop:DragDropManager.DropTargetAdvisor="{DynamicResource contactDragDrop}"          
          FlowDirection="{StaticResource flowDirection}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Menu>
            <Menu.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFEFEEF3" Offset="0.125"/>
                    <GradientStop Color="#FFD8DDE6" Offset="0.312"/>
                    <GradientStop Color="#FFECECEC" Offset="0.875"/>
                </LinearGradientBrush>
            </Menu.Background>
            <MenuItem Header="{StaticResource ChatWindow_MainMenu_File}">
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Save}" MenuItem.Click="SaveMenu_Click" />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_SaveAs}" MenuItem.Click="SaveAsMenu_Click" />
                <Separator />
                <MenuItem x:Name="mnuSendFile" Header="{StaticResource ChatWindow_MainMenu_SendAFile}" MenuItem.Click="SendFileMenu_Click" />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_OpenReceivedFiles}" MenuItem.Click="OpenReceivedFilesMenu_Click" />
                <Separator />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Close}" MenuItem.Click="CloseMenu_Click" />
            </MenuItem>
            <MenuItem Header="{StaticResource ChatWindow_MainMenu_Edit}">
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Undo}" InputGestureText="Ctrl+Z" IsEnabled="{Binding ElementName=txtMessageEditBox, Path=CanUndo}" Click="UndoMenu_Click" />
                <Separator />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Cut}" InputGestureText="Ctrl+X" Click="CutMenu_Click" />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Copy}" InputGestureText="Ctrl+C" Click="CopyMenu_Click" />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Paste}" InputGestureText="Ctrl+V" Click="PasteMenu_Click" />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Delete}" InputGestureText="Del" Click="DeleteMenu_Click" />
                <Separator />
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_SelectAll}" InputGestureText="Ctrl+A" Click="SelectAllMenu_Click" />
            </MenuItem>
            <MenuItem Header="{StaticResource ChatWindow_MainMenu_Actions}">
                <MenuItem x:Name="mnuInviteContact" Header="{StaticResource ChatWindow_MainMenu_InviteContact}" MenuItem.Click="InviteContactMenu_Click" />
                <MenuItem x:Name="mnuStartActivity" Header="{StaticResource ChatWindow_MainMenu_StartActivity}">
                    <MenuItem x:Name="mnuNoActivity" Header="{StaticResource ChatWindow_MainMenu_StartActivity_NoActivity}" IsEnabled="False" />
                </MenuItem>
            </MenuItem>
            <MenuItem Header="{StaticResource ChatWindow_MainMenu_Tools}">
                <MenuItem Header="{StaticResource ChatWindow_MainMenu_Settings}" MenuItem.Click="SettingsMenu_Click" />
            </MenuItem>
            <MenuItem Header="{StaticResource ChatWindow_MainMenu_Help}">
                <MenuItem Header="{StaticResource Global_Menu_About}" MenuItem.Click="AboutMenu_Click" />
            </MenuItem>
        </Menu>
        <Grid Margin="5" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition x:Name="messagePanel" Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Border Background="#FFFFFFE1"
                    Visibility="Collapsed" x:Name="buddyOfflineMessage">
                <TextBlock Margin="5" Focusable="False" Text="{Binding StringFormat='{}{0} appears to be offline.'}" />
            </Border>
            <controls:ChatTextBox Grid.Row="1" x:Name="chatTextBox" 
                                  Focusable="False" Height="Auto" Width="Auto" ItemEdit="chatTextBox_ItemEdit" />
            <Expander x:Name="expanderDisplayPics" Style="{DynamicResource displayPicsExpanderStyle}" Grid.Column="1" Grid.Row="1" 
                      ExpandDirection="Right" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed">
                <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Width="115">
                    <ItemsControl x:Name="displayPicsItemControl" Focusable="False" Margin="5" DataContext="{Binding}"                                   
                                  ItemsSource="{Binding Buddies}" >
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Margin="5,1,5,1" Tag="{Binding}">
                                    <Border.ToolTip>
                                        <ToolTip Style="{StaticResource BuddyToolTip}" />
                                    </Border.ToolTip>
                                    <StackPanel Orientation="Vertical" >
                                        <Viewbox HorizontalAlignment="Center" Height="70" Width="70" Margin="2">
                                            <Image>
                                                <Image.Style>
                                                    <Style TargetType="Image">
                                                        <Setter Property="Source" Value="{Binding Properties.DisplayImage}" />
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Properties.DisplayImage}" Value="{x:Null}">
                                                                <Setter Property="Source" Value="/Images/man.png" />
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </Image.Style>
                                            </Image>
                                        </Viewbox>
                                        <Grid>
                                            <Border Background="LightGray" CornerRadius="3" Height="20" />
                                            <TextBlock MaxWidth="80" HorizontalAlignment="Center" VerticalAlignment="Bottom" TextTrimming="CharacterEllipsis" Text="{Binding DisplayName}" Margin="5"/>
                                        </Grid>
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </Expander>
            <Border Grid.Row="2" Grid.ColumnSpan="2" MinHeight="150">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="26"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Border Height="30" Grid.ColumnSpan="2" >
                        <Border.Background>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFFCFCFC" Offset="0.087"/>
                                <GradientStop Color="#FFECECEC" Offset="0.478"/>
                            </LinearGradientBrush>
                        </Border.Background>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Horizontal" ToolTip="Send File">
                                <Button x:Name="btnSendFile" Style="{DynamicResource toolbarButton}" 
                                    ToolTip="Send File"
                                    Click="SendFile_Click" Foreground="Black">
                                    <Image Width="16" Height="16" Source="/Images/Upload.png" Stretch="Fill"/>
                                </Button>
                                <Button Style="{DynamicResource toolbarButton}" 
                                    Margin="5,0,0,0" ToolTip="Email"
                                    Click="SendEmail_Click" Foreground="Black">
                                    <Image Width="16" Height="16" Source="/Images/email.png" Stretch="Fill"/>
                                </Button>
                                <Button Style="{DynamicResource toolbarButton}" 
                                    Margin="5,0,0,0" ToolTip="Change Font"
                                    Click="ChangeFont_Click" Foreground="Black">
                                    <Image Width="16" Height="16" Source="/Images/Font.png" Stretch="Fill"/>
                                </Button>
                                <Button Style="{DynamicResource toolbarButton}" 
                                    Margin="5,0,0,0" ToolTip="Send Buzz"
                                    Click="SendBuzz_Click" Foreground="Black">
                                    <Image Width="16" Height="16" Source="/Images/Buzz.png" Stretch="Fill"/>
                                </Button>
                                <Button Style="{DynamicResource toolbarButton}" 
                                    Margin="5,0,0,0" ToolTip="Select an emoticon"
                                    Click="SendEmoticon_Click" Foreground="Black">
                                    <Image Width="16" Height="16" Source="/Images/Emoticons/Smile.png" Stretch="Fill"/>
                                </Button>
                            </StackPanel>
                            <controls:VoiceChatToolbarControl Margin="5,2,10,0" x:Name="voiceController" StartChat="VoiceChatToolbarControl_StartChat"  Grid.Column="2"/>
                        </Grid>
                    </Border>
                    <controls:MessageEditBox Margin="2,5,5,0" x:Name="txtMessageEditBox" MinHeight="70"
                                             MessageTyping="txtMessageEditBox_MessageTyping" 
                                             MessageSend="txtMessageEditBox_MessageSend" Grid.Row="1"
                                             PreviewKeyDown="txtMessageEditBox_PreviewKeyDown" />
                    <TextBlock Margin="0,10,0,0" x:Name="txbStatus" VerticalAlignment="Bottom" Grid.Row="2" Grid.ColumnSpan="2" Foreground="Black"/>
                </Grid>
            </Border>
            <GridSplitter ResizeDirection="Rows" HorizontalAlignment="Stretch"
                      Grid.Row="2" Grid.ColumnSpan="2" VerticalAlignment="Top" ResizeBehavior="PreviousAndCurrent"
                      Height="5" DragCompleted="GridSplitter_DragCompleted" />
        </Grid>
    </Grid>
</sticky:StickyWindowBase>
